const mysql = require('mysql');
// const mysqlConfig = require('../../resources/MysqlConfig');
const mysqlConfig = require('../../resources/MysqlConfig').development;
const {host, user, password, database, connectionLimit, port, waitForConnections} = mysqlConfig;
/**
 * 创建连接池
 * @type  func
 */
const pools = mysql.createPool({
    host: host,
    user: user,
    password: password,
    database: database,
    connectionLimit: connectionLimit,
    port: port,
    waitForConnections: waitForConnections,
    dateStrings: true,
    // debug:true
});
/**
 *  封装查询语句
 * @param params_sql  sql语句
 * @param params_where 占位符-查询条件；参数类型：数组 Array | []
 * @param callBack
 */


const getConnection = function (params_sql, params_where, callBack) {
    let sql = params_sql;
    let arr = params_where;
    pools.getConnection((err, connection) => {
        if (err) {
            console.error(err);
            return;
        }
        connection.query(sql, arr, callBack);
        connection.release();
    });
};

module.exports = getConnection;